package br.com.divulgaqui.persistence.daoimpl;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import br.com.divulgaqui.entity.Pessoa;
import br.com.divulgaqui.persistence.dao.ContaDAO;
import br.com.divulgaqui.persistence.dao.JPAGenericDAO;

public class ContaDAOImpl extends JPAGenericDAO<Pessoa> implements ContaDAO{

	public ContaDAOImpl(EntityManager entityManager) {
		super(entityManager);		
	}

	@Override
	public Pessoa recuperarPessoa(String senha, String email){
		StringBuilder sb = new StringBuilder("from Pessoa p \n");
		sb.append("left outer join fetch p.perfil \n");
		sb.append("where p.email = '"+email+"' \n");
		sb.append("and p.senha = '"+senha+"'");
		Query query = getEntityManager().createQuery(sb.toString());
		return (Pessoa) query.getSingleResult();
	}

}
